package com.mDigitalHealth.common;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.widget.Button;

public class HttpUtils {
	private Button requestButton = null;
	private static HttpResponse httpResponse = null;
	private static HttpEntity httpEntity = null;

	public static String sendHttpRequest(String url) {
		// 生成一个请求对象
		HttpGet httpGet = new HttpGet(url);
		// 生成一个Http客户端对象
		HttpClient httpClient = new DefaultHttpClient();
		// 使用Http客户端发送请求对象
		InputStream inputStream = null;

		String result = "";
		try {
			httpResponse = httpClient.execute(httpGet);
			httpEntity = httpResponse.getEntity();
			inputStream = httpEntity.getContent();
			BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
			String line = "";
			while ((line = reader.readLine()) != null) {
				result = result + line;
			}
			System.out.println(result);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				inputStream.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return result;
	}
}
